{% extends "base.html" %}

{% load bootstrap_form from bootstrap3 %}
{% load gross from prices_i18n %}
{% load discount_amount_for from prices %}
{% load i18n %}
{% load staticfiles %}

{% block title %}
    {% blocktrans trimmed context "Payment details page title" %}
        Pay for order {{ order }}
    {% endblocktrans %} — {{ block.super }}
{% endblock %}

{% block breadcrumb %}
    {% if order.user == user %}
    <ul class="breadcrumbs list-unstyled">
        <li><a href="/">
            {% trans "Home" context "Main navigation item" %}
        </a></li>
        <li><a href="{% url "profile:details" %}">
            {% trans "Your account" context "Main navigation item" %}
        </a></li>
        <li><a href="{{ order.get_absolute_url }}">
            {% blocktrans trimmed context "Payment details breadcrumb" %}
                Order {{ order }}
            {% endblocktrans %}
        </a></li>
    </ul>
    {% endif %}
{% endblock breadcrumb %}

{% block content %}
    <div class="row checkout">
        <div class="col-lg-10 offset-lg-1">
            {% if order.user == user or not order.is_fully_paid %}
                {% if not order.is_fully_paid %}
                       {% if waiting_payment %}
                            <h1>
                              {% trans "Payment pending" context "Payment details title" %}
                            </h1>
                            <form method="post" action="{% url 'order:cancel-payment' token=order.token %}" class="checkout-form">
                                {% csrf_token %}
                                <p>{% blocktrans trimmed context "Payment pending text" %}
                                    We are currently waiting for an external service to authorize
                                    your payment for this order.
                                {% endblocktrans %}</p>
                                <p>{% trans "Current status:" context "Payment status text" %}
                                    <br>
                                    <span class="label label-default">
                                    {{ waiting_payment.get_status_display }}
                                    </span>
                                </p>
                                <p>{%  blocktrans trimmed context "Payment pending text" %}
                                    Unless you are absolutely sure that the process will not complete
                                    (for example you have closed the browser window before paying),
                                    you should wait before attempting a new payment.
                                    Please be warned that if you try again and the previous
                                    transaction succeeds you might end up being charged twice.
                                {% endblocktrans %}</p>
                                {% bootstrap_form waiting_payment_form %}
                                <button type="submit" class="btn danger">
                                    {% trans "I understand, allow me to pay again" context "Payment pending action" %}
                                </button>
                            </form>
                        {% elif payment_form %}
                            <h1>
                                {% blocktrans trimmed context "Payment details title" %}
                                    Pay for order {{ order }}
                                {% endblocktrans %}
                            </h1>
                            <form method="post" action="{% url "order:payment" token=order.token %}" class="payment-method-form radio">
                              {% csrf_token %}
                              {{ payment_form }}
                              {% block form_submit %}
                                    <button type="submit" class="btn primary">
                                        {% trans "Proceed to payment" context "Payment details primary action" %}
                                    </button>
                              {% endblock %}
                            </form>
                        {% else %}
                            <p>{% trans "You've authorized transaction. Order is in processing" context "Payment details text" %}</p>
                        {% endif %}
                {% endif %}
            {% endif %}
            {% include 'order/order-details.html' %}
        </div>
    </div>
{% endblock content %}
